<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="admin::header">
</head>
<section>
    <script>
        updatePassword = function () {

            if ($("#old_password").val()==""){
                alert("旧密码不能为空！");
                return;
            }
            if ($("#new_password").val()==""){
                alert("新密码不能为空！");
                return;
            }
            if ($("#re_password").val()==""){
                alert("确认密码不能为空！");
                return;
            }
            if ($("#new_password").val()!=$("#re_password").val()){
                alert("两次密码不一致！");
                $("#new_password").val("");
                $("#re_password").val("");
                return;
            }
            $.ajax({
                type:"POST",
                url:"/exam/common/updatePassword",
                data:{
                    old_password:$("#old_password").val(),
                    new_password:$("#new_password").val()
                },
                dataType:"json",
                success:function (data) {
                    if (data == null){
                        alert("您未登陆，请先登录!");
                        window.location.href = ("/exam/page/login");
                    }else {
                        $.each(data,function (key,value) {
                            alert(value);
                            $("#old_password").val("");
                            $("#new_password").val("");
                            $("#re_password").val("");
                        });
                    }
                }
            });
        }
    </script>
</section>
<body class="sidebar-fixed header-fixed">
<div class="page-wrapper">
    <!--导入上边栏-->
    <nav class="navbar page-header" th:include="admin::admin-navbar"></nav>
    <!--导入侧边栏-->
    <div class="main-container">
        <div class="sidebar" th:include="admin::admin-sidebar"></div>
        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header bg-light">
                                修改密码
                            </div>

                            <div class="card-body">
                                <div class="row mb-5">
                                    <div class="col-md-4 mb-4">
                                        <div>Profile Information</div>
                                        <br />
                                        <div class="text-muted small">在这里，你可以修改你的密码</div>
                                    </div>

                                    <div class="col-md-8">
                                        <div class="row">
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label for="old_password" class="form-control-label">原密码</label>
                                                    <input type="password" id="old_password" class="form-control" value="" required>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label for="new_password" class="form-control-label">新密码</label>
                                                    <input type="password" id="new_password" class="form-control" value="" required>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label for="re_password" class="form-control-label">确认密码</label>
                                                    <input type="password" id="re_password" class="form-control" value="" required>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <hr>
                            </div>

                            <div class="card-footer bg-light text-right">
                                <button type="submit" class="btn btn-primary" th:onclick="'javascript:updatePassword()'">Save Changes</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
